<div class="layui-fluid layui-anim febs-anim-up" id="febs-index" lay-title="评分页">
    <div class="layui-row layui-col-space8 febs-container">
        <div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-body layui-anim layui-anim-fadein">
                    <div class="layui-row welcome-info">
                        <div class="layui-col-md6 layui-col-sm12 layui-col-xs12">
                            <div class="layui-row welcome-info-wrapper">
                                <div class="user-header">
                                    </i><a id="detail-back" href="javascript:history.go(-1);" ><h3>返回上一页</h3></a>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6 layui-col-sm12 layui-col-xs12">
                            <div class="layui-col-md-offset5">
                                <table class="login-count-table" id="table_case">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 layui-col-sm6 layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form" lay-filter="example" method="post">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;font-size: small">
                            <legend style="font-size: medium;font-weight: bold">提案详情:</legend>
                        </fieldset>
                        <div class="layui-form">
                            <label class="layui-form-label">提案编号</label>
                            <div class="layui-input-block">
                                <input type="text" name="ppsNo" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">提案名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="ppsName" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">所属单位</label>
                            <div class="layui-input-block">
                                <input type="text" name="deptname" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">提案人</label>
                            <div class="layui-input-block">
                                <input type="text" name="empnm" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">提案日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="ppsDate" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">提案事由</label>
                            <div class="layui-input-block">
                                <input type="text" name="reasonDesc" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">现状缺点</label>
                            <div class="layui-input-block">
                                <input type="text" name="defectDesc" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">改进意见</label>
                            <div class="layui-input-block">
                                <input type="text" name="proposeDesc" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <label class="layui-form-label">预期效果</label>
                            <div class="layui-input-block">
                                <input type="text" name="resulrDesc" readonly="true" class="layui-input" style="background-color: #cccccc">
                            </div><br>
                            <hr>
                            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                                <legend>评分:</legend>
                            </fieldset>
                            <label class="layui-form-label">1、效益性:</label>
                            <div name = "benefit_score" id="benefit_score" ></div>
                            <fieldset class="layui-elem-field" >
                                <legend style="font-size: small">
                                </legend>
                                <div class="layui-field-box" style="font-size: small">能利用制工具优化制程，或藉由不同的设计思维创造应用价值，进而提升生产效益操作符合工厂自动化趋势，实务应用性广泛，或对产品质量及人员操作安全有所有提升，有效降低质量不良或工伤发生可能</div>
                            </fieldset>
                            <label class="layui-form-label">2、技术性:</label>
                            <div name = "technical_score" id="technical_score"></div>
                            <fieldset class="layui-elem-field" >
                                <legend style="font-size: small"></legend>
                                <div class="layui-field-box" style="font-size: small">技术应用成熟度及作品功能性、材料、技术等</div>
                            </fieldset>
                            <label class="layui-form-label">3、创意性:</label>
                            <div name = "creativity_score" id="creativity_score"></div>
                            <fieldset class="layui-elem-field" >
                                <legend style="font-size: small">
                                </legend>
                                <div class="layui-field-box" style="font-size: small">评比时，制工具模型精致度、简报完整度</div>
                            </fieldset>
                            <label class="layui-form-label" id="remark1">其他意见或建议:</label>
                            <div class="layui-input-block" >
                                <textarea id="remark2" name="remark" placeholder="请输入意见或建议" class="layui-textarea"></textarea>
                            </div>
                            <input name="benefit_score" id="benefit" type="hidden" value="5">
                            <input name="technical_score" id="technical" type="hidden" value="5">
                            <input name="creativity_score" id="creativity" type="hidden" value="5">
                            <input name="orgId" id="orgId" type="hidden" >
                        </div><br>
                        <div align="center" id="subm">
                            <input class="layui-btn layui-btn-danger layui-border-red" type="button" name="Submit" onclick="javascript:history.back(-1);" value="返回上一页">
                            <button  class="layui-btn layui-btn-normal layui-border-blue" lay-submit lay-filter="subm">提交评价</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript"  th:inline="javascript">
    // document.querySelector('#')

    layui.use(['febs','rate', 'form', 'jquery', 'layer', 'table'], function(){
        let $ = layui.$ //重点处
            ,rate = layui.rate
            ,form = layui.form
            ,layer = layui.layer
            ,table = layui.table
            ,url = window.location.href
            ,febs = layui.febs
            ,ppsNo = url.substring(url.lastIndexOf("/") + 1)
            ,benefit = 5
            ,technical = 5
            ,creativity = 5;
        function getData() {
            $.ajax({
                url: "/remark/pps/" + ppsNo,
                method:'get',
                dataType:'text',
                contentType: 'application/json',
                timeout:2000,
                success:function(res){
                    var result = JSON.parse(res)
                    if(result.code == 0){
                        var data = result.data;
                        if(result.count == 1){
                            $("#subm").hide()
                            $("#remark2").html(data.remark).attr("readOnly", true).attr("style", "background-color: #cccccc")
                            benefit = data.benefit
                            technical = data.technical
                            creativity = data.creativity
                        } else {
                            $("#subm").show()
                            $("#remark1").show()
                            $("#remark2").show()
                        }

                        //评价星星
                        rate.render({
                            elem: '#benefit_score'
                            ,value: benefit //初始值
                            ,text: true //开启文本
                            ,choose: function (value){
                                $("#benefit").val(value);
                            }
                        });
                        rate.render({
                            elem: '#technical_score'
                            ,value: technical //初始值
                            ,text: true //开启文本
                            ,choose: function (value){
                                $("#technical").val(value);
                            }
                        });
                        rate.render({
                            elem: '#creativity_score'
                            ,value: creativity //初始值
                            ,text: true //开启文本
                            ,choose: function (value){
                                $("#creativity").val(value);
                            }
                        });

                        //表单赋值
                        $(function(){
                            form.val('example', {
                                "ppsNo": data.ppsNo
                                ,"ppsName": data.ppsName
                                ,"orgId": data.orgId
                                ,"empnm": data.empnm
                                ,"ppsDate": data.ppsDate
                                ,"reasonDesc": data.reasonDesc
                                ,"defectDesc": data.defectDesc
                                ,"proposeDesc": data.proposeDesc
                                ,"resulrDesc": data.resulrDesc
                                ,"deptname": data.deptname
                            });
                        });
                    }
                    else
                        alert(res.msg);
                },
                error:function (data) {
                    alert(data)
                }
            }) ;
        }
        getData();

        document.body.eventBus.addEvent('refreshRemarkDetail' + ppsNo, function() {
            getData()
        })

        //监听表格点击事件,点击行
        form.on('submit(subm)', function(data){
            $.ajax({
                url: "/remark/save",
                method:'post',
                data:JSON.stringify(data.field),
                dataType:'text',
                contentType: 'application/json',
                timeout:2000,
                success:function(res){
                    let result = JSON.parse(res)
                    if (result.code == 200) {
                        layer.msg(result.message)
                    } else
                        layer.msg(result.message)
                },
                error:function (data) {
                        alert(data)
                }
            }) ;
            setTimeout(function (){//removeEvent
                document.body.eventBus.removeEvent('refreshRemarkDetail')
                document.body.eventBus.fireEvent('refreshRemarkList')
                window.location.href = url.substring(0, url.lastIndexOf("/"));
            }, 2000);//两秒后返回评价列表页面
            return false;
        });


    });

</script>